/*LICENSE_BEGIN
 * ******************************************************************
 * Copyright 2006 by the Dainamite Robocup-Team at the
 * DAI-Labor, TU-Berlin (www.dai-labor.de)
 * 
 * Members of Dainamite are:
 * Holger Endert
 * Robert Wetzker
 * Thomas Karbe
 * Axel Heßler
 * Philippe Bütter
 * Felix Brossmann
 * 
 * Licensed under the GNU GPL (General Public License) Free Software 
 * License, Version 2. You may use this file only in compliance with 
 * the License. You may obtain a copy of the License at:
 * 
 * http://www.fsf.org/licensing/licenses/gpl.txt
 * ******************************************************************
LICENSE_END*/
package robocup.component.tactics;

import robocup.component.SConf;
import robocup.component.ControllerNumbers.STAMINA_LEVEL;
import robocup.component.actionfactories.BasicActionFactory;
import robocup.component.geometry.Vektor;

/**
 * The BeforeKickOffState is triggered for all Situations with play_mode 
 * BEFORE_KICK_OFF. It's the the state that lets the player move to its start 
 * position. All players will be turned in the direction of the opponent's goal.
 * However, if its our kick off player number 10 will be the fastest to the ball
 * and this state will not be triggered for him.
 */
public class BeforeKickOffState extends AbstractState {

	/**
	 * BeforeKickOffState is used for all players and lets them turn
	 * to the opp. goal.
	 * 
	 * @param parent -
	 *            the StateEvaluation (parent) object
	 */
	public BeforeKickOffState(StateEvaluation parent) {

		super(parent);
		this.state = STATES.BEFORE_KICKOFF;
	}

	@Override
	public boolean preCondition() {

		return checkPlayMode() 
      && !this.checkIAmFastestToBall()
			&& !getWorld().canKick();
	}

	/**
	 * This state will always succeed.
	 */
	@Override
	protected double successProbability() {

		return 1;
	}

	/**
	 * Because this is a dummy state - the values for assessment are very low!
	 */
	@Override
	protected double successBenefit() {

		return 1;
	}

  /**
   * Turn to the opponents goal. or go to the ball if number 10.
   */
	@Override
	public void calculateMainAction() {
		Vektor lookHere = SConf.getInstance().GOAL_POS_OTHER;

		if (this.getPlayer().getNumber() == 10)
			mainAction = BasicActionFactory.moveToPos(this.getPlayer(),
					new Vektor(), 1, STAMINA_LEVEL.MAX);
		else
			mainAction = BasicActionFactory.turnBodyToPoint(getWorld(),
					lookHere);
	}

}
